/*
 @name: layer
 @version: 4
 @date: 2023.4.2
 @update: yuguoliang
 @blog: https://www.cssw3c.com/
 */

;(function(window, undefined) {
    var Dom7 = (function() {
        var Dom7 = function(arr) {
            var _this = this, i = 0;
            // Create array-like object
            for (i = 0; i < arr.length; i++) {
                _this[i] = arr[i];
            }
            _this.length = arr.length;
            // Return collection with methods
            return this;
        };
        var $ = function(selector, context) {
            var arr = [], i = 0;
            if (selector && !context) {
                if (selector instanceof Dom7) {
                    return selector;
                }
            }
            if (selector) {
                // String
                if (typeof selector === 'string') {
                    var els, tempParent, html = selector.trim();
                    if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
                        var toCreate = 'div';
                        if (html.indexOf('<li') === 0) toCreate = 'ul';
                        if (html.indexOf('<tr') === 0) toCreate = 'tbody';
                        if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr';
                        if (html.indexOf('<tbody') === 0) toCreate = 'table';
                        if (html.indexOf('<option') === 0) toCreate = 'select';
                        tempParent = document.createElement(toCreate);
                        tempParent.innerHTML = selector;
                        for (i = 0; i < tempParent.childNodes.length; i++) {
                            arr.push(tempParent.childNodes[i]);
                        }
                    } else {
                        if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) {
                            // Pure ID selector
                            els = [document.getElementById(selector.split('#')[1])];
                        } else {
                            // Other selectors
                            els = (context || document).querySelectorAll(selector);
                        }
                        for (i = 0; i < els.length; i++) {
                            if (els[i]) arr.push(els[i]);
                        }
                    }
                } else if ($.isFunction(selector)) return $(document).ready(selector);
                // Node/element
                else if (selector.nodeType || selector === window || selector === document) {
                    arr.push(selector);
                }
                //Array of elements or instance of Dom
                else if (selector.length > 0 && selector[0].nodeType) {
                    for (i = 0; i < selector.length; i++) {
                        arr.push(selector[i]);
                    }
                }
            }
            return new Dom7(arr);
        };
        Dom7.prototype = {
            // Classes and attriutes
            addClass: function(className) {
                if (typeof className === 'undefined') {
                    return this;
                }
                var classes = className.split(' ');
                for (var i = 0; i < classes.length; i++) {
                    for (var j = 0; j < this.length; j++) {
                        this[j].classList.add(classes[i]);
                    }
                }
                return this;
            },
            removeClass: function(className) {
                var classes = className.split(' ');
                for (var i = 0; i < classes.length; i++) {
                    for (var j = 0; j < this.length; j++) {
                        this[j].classList.remove(classes[i]);
                    }
                }
                return this;
            },
            hasClass: function(className) {
                if (!this[0]) return false;
                else return this[0].classList.contains(className);
            },
            toggleClass: function(className) {
                var classes = className.split(' ');
                for (var i = 0; i < classes.length; i++) {
                    for (var j = 0; j < this.length; j++) {
                        this[j].classList.toggle(classes[i]);
                    }
                }
                return this;
            },
            attr: function(attrs, value) {
                if (arguments.length === 1 && typeof attrs === 'string') {
                    // Get attr
                    if (this[0]) return this[0].getAttribute(attrs);
                    else return undefined;
                } else {
                    // Set attrs
                    for (var i = 0; i < this.length; i++) {
                        if (arguments.length === 2) {
                            // String
                            this[i].setAttribute(attrs, value);
                        } else {
                            // Object
                            for (var attrName in attrs) {
                                this[i][attrName] = attrs[attrName];
                                this[i].setAttribute(attrName, attrs[attrName]);
                            }
                        }
                    }
                    return this;
                }
            },
            removeAttr: function(attr) {
                for (var i = 0; i < this.length; i++) {
                    this[i].removeAttribute(attr);
                }
                return this;
            },
            data: function(key, value) {
                if (typeof value === 'undefined') {
                    // Get value
                    if (this[0]) {
                        var dataKey = this[0].getAttribute('data-' + key);
                        if (dataKey) return dataKey;
                        else if (this[0].dom7ElementDataStorage && (key in this[0].dom7ElementDataStorage)) return this[0].dom7ElementDataStorage[key];
                        else return undefined;
                    } else return undefined;
                } else {
                    // Set value
                    for (var i = 0; i < this.length; i++) {
                        var el = this[i];
                        if (!el.dom7ElementDataStorage) el.dom7ElementDataStorage = {};
                        el.dom7ElementDataStorage[key] = value;
                    }
                    return this;
                }
            },
            // Transforms
            transform: function(transform) {
                for (var i = 0; i < this.length; i++) {
                    var elStyle = this[i].style;
                    elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
                }
                return this;
            },
            transition: function(duration) {
                if (typeof duration !== 'string') {
                    duration = duration + 'ms';
                }
                for (var i = 0; i < this.length; i++) {
                    var elStyle = this[i].style;
                    elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
                }
                return this;
            },
            // Sizing/Styles
            width: function() {
                if (this[0] === window) {
                    return window.innerWidth;
                } else {
                    if (this.length > 0) {
                        return parseFloat(this.css('width'));
                    } else {
                        return null;
                    }
                }
            },
            outerWidth: function(includeMargins) {
                if (this.length > 0) {
                    if (includeMargins)
                        return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left'));
                    else
                        return this[0].offsetWidth;
                } else return null;
            },
            height: function() {
                if (this[0] === window) {
                    return window.innerHeight;
                } else {
                    if (this.length > 0) {
                        return parseFloat(this.css('height'));
                    } else {
                        return null;
                    }
                }
            },
            outerHeight: function(includeMargins) {
                if (this.length > 0) {
                    if (includeMargins)
                        return this[0].offsetHeight + parseFloat(this.css('margin-top')) + parseFloat(this.css('margin-bottom'));
                    else
                        return this[0].offsetHeight;
                } else return null;
            },
            offset: function() {
                if (this.length > 0) {
                    var el = this[0];
                    var box = el.getBoundingClientRect();
                    var body = document.body;
                    var clientTop = el.clientTop || body.clientTop || 0;
                    var clientLeft = el.clientLeft || body.clientLeft || 0;
                    var scrollTop = window.pageYOffset || el.scrollTop;
                    var scrollLeft = window.pageXOffset || el.scrollLeft;
                    return {
                        top: box.top + scrollTop - clientTop,
                        left: box.left + scrollLeft - clientLeft
                    };
                } else {
                    return null;
                }
            },
            css: function(props, value) {
                var i;
                if (arguments.length === 1) {
                    if (typeof props === 'string') {
                        if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
                    } else {
                        for (i = 0; i < this.length; i++) {
                            for (var prop in props) {
                                this[i].style[prop] = props[prop];
                            }
                        }
                        return this;
                    }
                }
                if (arguments.length === 2 && typeof props === 'string') {
                    for (i = 0; i < this.length; i++) {
                        this[i].style[props] = value;
                    }
                    return this;
                }
                return this;
            },
            //Dom manipulation
            each: function(callback) {
                for (var i = 0; i < this.length; i++) {
                    callback.call(this[i], i, this[i]);
                }
                return this;
            },
            html: function(html) {
                if (typeof html === 'undefined') {
                    return this[0] ? this[0].innerHTML : undefined;
                } else {
                    for (var i = 0; i < this.length; i++) {
                        this[i].innerHTML = html;
                    }
                    return this;
                }
            },
            text: function text(text) {
                if (typeof text === 'undefined') {
                    return this[0] ? this[0].textContent.trim() : null;
                }

                for (let i = 0; i < this.length; i += 1) {
                    this[i].textContent = text;
                }

                return this;
            },
            is: function(selector) {
                if (!this[0]) return false;
                var compareWith, i;
                if (typeof selector === 'string') {
                    var el = this[0];
                    if (el === document) return selector === document;
                    if (el === window) return selector === window;

                    if (el.matches) return el.matches(selector);
                    else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
                    else if (el.mozMatchesSelector) return el.mozMatchesSelector(selector);
                    else if (el.msMatchesSelector) return el.msMatchesSelector(selector);
                    else {
                        compareWith = $(selector);
                        for (i = 0; i < compareWith.length; i++) {
                            if (compareWith[i] === this[0]) return true;
                        }
                        return false;
                    }
                } else if (selector === document) return this[0] === document;
                else if (selector === window) return this[0] === window;
                else {
                    if (selector.nodeType || selector instanceof Dom7) {
                        compareWith = selector.nodeType ? [selector] : selector;
                        for (i = 0; i < compareWith.length; i++) {
                            if (compareWith[i] === this[0]) return true;
                        }
                        return false;
                    }
                    return false;
                }

            },
            index: function() {
                if (this[0]) {
                    var child = this[0];
                    var i = 0;
                    while ((child = child.previousSibling) !== null) {
                        if (child.nodeType === 1) i++;
                    }
                    return i;
                } else return undefined;
            },
            eq: function(index) {
                if (typeof index === 'undefined') return this;
                var length = this.length;
                var returnIndex;
                if (index > length - 1) {
                    return new Dom7([]);
                }
                if (index < 0) {
                    returnIndex = length + index;
                    if (returnIndex < 0) return new Dom7([]);
                    else return new Dom7([this[returnIndex]]);
                }
                return new Dom7([this[index]]);
            },
            append: function(newChild) {
                var i, j;
                for (i = 0; i < this.length; i++) {
                    if (typeof newChild === 'string') {
                        var tempDiv = document.createElement('div');
                        tempDiv.innerHTML = newChild;
                        while (tempDiv.firstChild) {
                            this[i].appendChild(tempDiv.firstChild);
                        }
                    } else if (newChild instanceof Dom7) {
                        for (j = 0; j < newChild.length; j++) {
                            this[i].appendChild(newChild[j]);
                        }
                    } else {
                        this[i].appendChild(newChild);
                    }
                }
                return this;
            },
            prepend: function(newChild) {
                var i, j;
                for (i = 0; i < this.length; i++) {
                    if (typeof newChild === 'string') {
                        var tempDiv = document.createElement('div');
                        tempDiv.innerHTML = newChild;
                        for (j = tempDiv.childNodes.length - 1; j >= 0; j--) {
                            this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
                        }
                        // this[i].insertAdjacentHTML('afterbegin', newChild);
                    } else if (newChild instanceof Dom7) {
                        for (j = 0; j < newChild.length; j++) {
                            this[i].insertBefore(newChild[j], this[i].childNodes[0]);
                        }
                    } else {
                        this[i].insertBefore(newChild, this[i].childNodes[0]);
                    }
                }
                return this;
            },
            insertBefore: function(selector) {
                var before = $(selector);
                for (var i = 0; i < this.length; i++) {
                    if (before.length === 1) {
                        before[0].parentNode.insertBefore(this[i], before[0]);
                    } else if (before.length > 1) {
                        for (var j = 0; j < before.length; j++) {
                            before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]);
                        }
                    }
                }
            },
            insertAfter: function(selector) {
                var after = $(selector);
                for (var i = 0; i < this.length; i++) {
                    if (after.length === 1) {
                        after[0].parentNode.insertBefore(this[i], after[0].nextSibling);
                    } else if (after.length > 1) {
                        for (var j = 0; j < after.length; j++) {
                            after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling);
                        }
                    }
                }
            },
            next: function(selector) {
                if (this.length > 0) {
                    if (selector) {
                        if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) return new Dom7([this[0].nextElementSibling]);
                        else return new Dom7([]);
                    } else {
                        if (this[0].nextElementSibling) return new Dom7([this[0].nextElementSibling]);
                        else return new Dom7([]);
                    }
                } else return new Dom7([]);
            },
            nextAll: function(selector) {
                var nextEls = [];
                var el = this[0];
                if (!el) return new Dom7([]);
                while (el.nextElementSibling) {
                    var next = el.nextElementSibling;
                    if (selector) {
                        if ($(next).is(selector)) nextEls.push(next);
                    } else nextEls.push(next);
                    el = next;
                }
                return new Dom7(nextEls);
            },
            prev: function(selector) {
                if (this.length > 0) {
                    if (selector) {
                        if (this[0].previousElementSibling && $(this[0].previousElementSibling).is(selector)) return new Dom7([this[0].previousElementSibling]);
                        else return new Dom7([]);
                    } else {
                        if (this[0].previousElementSibling) return new Dom7([this[0].previousElementSibling]);
                        else return new Dom7([]);
                    }
                } else return new Dom7([]);
            },
            prevAll: function(selector) {
                var prevEls = [];
                var el = this[0];
                if (!el) return new Dom7([]);
                while (el.previousElementSibling) {
                    var prev = el.previousElementSibling;
                    if (selector) {
                        if ($(prev).is(selector)) prevEls.push(prev);
                    } else prevEls.push(prev);
                    el = prev;
                }
                return new Dom7(prevEls);
            },
            parent: function(selector) {
                var parents = [];
                for (var i = 0; i < this.length; i++) {
                    if (selector) {
                        if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
                    } else {
                        parents.push(this[i].parentNode);
                    }
                }
                return $($.unique(parents));
            },
            parents: function(selector) {
                var parents = [];
                for (var i = 0; i < this.length; i++) {
                    var parent = this[i].parentNode;
                    while (parent) {
                        if (selector) {
                            if ($(parent).is(selector)) parents.push(parent);
                        } else {
                            parents.push(parent);
                        }
                        parent = parent.parentNode;
                    }
                }
                return $($.unique(parents));
            },
            find: function(selector) {
                var foundElements = [];
                for (var i = 0; i < this.length; i++) {
                    var found = this[i].querySelectorAll(selector);
                    for (var j = 0; j < found.length; j++) {
                        foundElements.push(found[j]);
                    }
                }
                return new Dom7(foundElements);
            },
            children: function(selector) {
                var children = [];
                for (var i = 0; i < this.length; i++) {
                    var childNodes = this[i].childNodes;

                    for (var j = 0; j < childNodes.length; j++) {
                        if (!selector) {
                            if (childNodes[j].nodeType === 1) children.push(childNodes[j]);
                        } else {
                            if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) children.push(childNodes[j]);
                        }
                    }
                }
                return new Dom7($.unique(children));
            },
            remove: function() {
                for (var i = 0; i < this.length; i++) {
                    if (this[i].parentNode) this[i].parentNode.removeChild(this[i]);
                }
                return this;
            },
            empty: function() {
                for (let i = 0; i < this.length; i += 1) {
                    const el = this[i];
                    if (el.nodeType === 1) {
                        for (let j = 0; j < el.childNodes.length; j += 1) {
                            if (el.childNodes[j].parentNode) {
                                el.childNodes[j].parentNode.removeChild(el.childNodes[j]);
                            }
                        }
                        el.textContent = '';
                    }
                }
                return this;
            },
            empty2: function(flag) {
                for (let i = 0; i < this.length; i += 1) {
                    const el = this[i];
                    if (el.nodeType === 1) {
                        for (let j = 0; j < el.childNodes.length; j += 1) {
                            if (flag) {
                                if (el.childNodes[j].hasChildNodes() && !!el.childNodes[j].parentNode) {
                                    el.childNodes[j].parentNode.removeChild(el.childNodes[j]);
                                }
                            } else {
                                if (el.childNodes[j].parentNode) {
                                    el.childNodes[j].parentNode.removeChild(el.childNodes[j]);
                                }
                            }
                        }
                        if (!flag) {
                            el.textContent = '';
                        }
                    }
                }
                return this;
            },
            add: function() {
                var dom = this;
                var i, j;
                for (i = 0; i < arguments.length; i++) {
                    var toAdd = $(arguments[i]);
                    for (j = 0; j < toAdd.length; j++) {
                        dom[dom.length] = toAdd[j];
                        dom.length++;
                    }
                }
                return dom;
            },
            siblings: function(selector) {
                return this.nextAll(selector).add(this.prevAll(selector));

            }
        };
        $.fn = Dom7.prototype;
        $.extend = $.fn.extend = function() {
            var options, name, src, copy, copyIsArray, clone,
                target = arguments[0] || {},
                i = 1,
                length = arguments.length,
                deep = false;
            if (typeof target === 'boolean') {
                deep = target;
                target = arguments[1] || {};

                // 将i赋值为2，跳过前两个参数
                i = 2;
            }
            if (typeof target !== 'object' && !$.isFunction(target)) {
                target = {};
            }
            if (length === i) {
                target = this;
                --i;
            }
            for (; i < length; i++) {
                if ((options = arguments[i]) != null) {
                    for (name in options) {
                        src = target[name];
                        copy = options[name];
                        if (target === copy) {
                            continue;
                        }
                        if (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy)))) {
                            if (copyIsArray) {
                                copyIsArray = false;
                                clone = src && $.isArray(src) ? src : [];
                            } else {
                                clone = src && $.isPlainObject(src) ? src : {};
                            }
                            target[name] = $.extend(deep, clone, copy);
                        } else if (copy !== undefined) {
                            target[name] = copy;
                        }
                    }
                }
            }
            return target;
        };
        $.fn.extend({
            ready: function(callback) {
                // need to check if document.body exists for IE as that browser reports
                // document ready when it hasn't yet created the body element
                var readyRE = /complete|loaded|interactive/;
                if (readyRE.test(document.readyState) && document.body) callback($);
                else document.addEventListener('DOMContentLoaded', function() {
                    callback($);
                }, false);
                return this;
            },
            val: function(value) {
                var ret, elem = this[0];
                if (!arguments.length) {
                    if (elem) {
                        ret = elem.value;
                        return typeof ret === 'string' ? ret.replace(/\r\n/g, '') : ret == null ? '' : ret;
                    }
                    return;
                }
                return this.each(function() {
                    var val;
                    //元素不为DOM节点则返回
                    if (this.nodeType !== 1) {
                        return;
                    }
                    val = value;
                    if (val == null) {
                        val = '';
                    } else if (typeof val === 'number') {
                        val += '';
                    }
                    this.value = val;
                });
            }
        });
        $.extend({
            trim: function(str) {
                return str.replace(/(^\s*)|(\s*$)/g, '');
            },
            getTouchPosition: function(e) {
                e = e.originalEvent || e; //jquery wrap the originevent
                if (e.type === 'touchstart' || e.type === 'touchmove' || e.type === 'touchend') {
                    return {
                        x: e.targetTouches[0].pageX,
                        y: e.targetTouches[0].pageY
                    };
                } else {
                    return {
                        x: e.pageX,
                        y: e.pageY
                    };
                }
            },
            parseJSON: function(data) {
                if (typeof data !== 'string' || !data) {
                    return null;
                }

                // Make sure leading/trailing whitespace is removed (IE can't handle it)
                data = data.trim();

                // Attempt to parse using the native JSON parser first
                if (window.JSON && window.JSON.parse) {
                    return window.JSON.parse(data);
                }

                console.log('Invalid JSON: ' + data);
            },
            isTouch: function() {
                return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch);
            },
            touchEvents: function() {
                return {
                    start: $.isTouch ? 'touchstart' : 'mousedown',
                    move: $.isTouch ? 'touchmove' : 'mousemove',
                    end: $.isTouch ? 'touchend' : 'mouseup'
                };
            },
            unique: function(arr) {
                var unique = [];
                for (var i = 0; i < arr.length; i++) {
                    if (unique.indexOf(arr[i]) === -1) unique.push(arr[i]);
                }
                return unique;
            },
            isArray: function(arg) {
                if (typeof arg === 'object') {
                    return Object.prototype.toString.call(arg) === '[object Array]';
                }
                return false;
            },
            likeArray: function(obj) {
                if (obj &&                                // o is not null, undefined, etc.
                    typeof obj === 'object' &&            // o is an object
                    isFinite(obj.length) &&               // o.length is a finite number
                    obj.length >= 0 &&                    // o.length is non-negative
                    obj.length === Math.floor(obj.length) &&  // o.length is an integer
                    obj.length < 4294967296)              // o.length < 2^32
                    return true;                        // Then o is array-like
                else
                    return false;
            },
            isObject: function(arg) {
                if (typeof arg === 'object') {
                    return Object.prototype.toString.call(arg) === '[object Object]';
                }
                return false;
            },
            isPlainObject: function(obj) {
                if (!this.isObject(obj) || obj.nodeType || this.isWindow(obj)) {
                    return false;
                }
                try {
                    if (obj.constructor && !UtilYgl.hasOwn.call(obj, 'constructor') && !UtilYgl.hasOwn.call(obj.constructor.prototype, 'isPrototypeOf')) {
                        return false;
                    }
                } catch (e) {
                    return false;
                }
                var key;
                for (key in obj) {
                }
                return key === undefined || UtilYgl.hasOwn.call(obj, key);
            },
            isFunction: function(obj) {
                if (typeof obj === 'function') {
                    return Object.prototype.toString.call(obj) === '[object Function]';
                }
                return false;
            },
            isWindow: function(obj) {
                return obj != null && obj == obj.window;
            },
            getWindow: function(elem) {
                //如果是elem是window对象，则直接返回elem
                //否则如果elem表示整个文档，则返回elem.defaultView(即window对象)，否则返回elem.parentWindow，如果elem.parentWindow不存在则返回false
                return $.isWindow(elem) ? elem : elem.nodeType === 9 ? elem.defaultView || elem.parentWindow : false;
            },
            each: function(object, callback) {
                var i, key;
                if (this.likeArray(object)) {
                    for (i = 0; i < object.length; i++)
                        if (callback.call(object[i], i, object[i]) === false) return object;
                } else {
                    for (key in object)
                        if (callback.call(object[key], key, object[key]) === false) return object;
                }
                return object;
            },
            type: function(obj) {
                var class2type = {}, toString = class2type.toString;
                $.each('Boolean Number String Function Array Date RegExp Object Error'.split(' '), function(i, name) {
                    class2type['[object ' + name + ']'] = name.toLowerCase();
                });
                return obj == null ? String(obj) : class2type[toString.call(obj)] || 'object';
            },
            inArray: function(elem, array, i) {
                var len, indexOf = Array.prototype.indexOf;
                if (array) {
                    if (indexOf) {
                        return indexOf.call(array, elem, i);
                    }
                    len = array.length;
                    i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
                    for (; i < len; i++) {
                        // Skip accessing in sparse arrays
                        if (i in array && array[i] === elem) {
                            return i;
                        }
                    }
                }
                return -1;
            }
        });
        $.each(['Left', 'Top'], function(i, name) {    //在jQuery.fn加上.scrollLeft()和.scrollTop()方法     对于scrollLeft来说，i为0，对于scrollTop来说，i为1
            var method = 'scroll' + name;
            $.fn[method] = function(val) {                //挂在实例上面
                var elem, win;
                if (val === undefined) {                        //如果没有传入val参数
                    elem = this[0];
                    if (!elem) {                                //如果没有匹配元素
                        return null;                                //则返回null
                    }
                    win = $.getWindow(elem);                    //获取window对象，如果参数elem是window对象，则返回window对象，否则返回false
                    // Return the scroll offset
                    return win ? ('pageXOffset' in win) ? win[i ? 'pageYOffset' : 'pageXOffset'] :
                            document.compatMode === 'CSS1Compat' && win.document.documentElement[method] ||
                            win.document.body[method] :
                        elem[method];                            //用于读取window对象、document对象、元素的滚动偏移
                }
                //执行到这里，则表示是设置滚动了
                // Set the scroll offset
                return this.each(function() {                    //遍历匹配元素，设置每个元素的滚动偏移
                    win = $.getWindow(this);

                    if (win) {                                //如果是window对象，则调用scrollTo()滚动到执行的位置，该方法两个参数都是必须的。
                        win.scrollTo(
                            !i ? val : $(win).scrollLeft(),    //这两个参数是必填的
                            i ? val : $(win).scrollTop()
                        );

                    } else {
                        this[method] = val;                    //否则设置元素的scrollLeft、scrollTop属性。
                    }
                });
            };
        });
        return $;
    })();
    window.Dom7 = window.$$ = Dom7;
})(window);

//dom7-event
;(function($) {
    var _zid = 1, undefined,
        slice = Array.prototype.slice,
        isFunction = $.isFunction,
        isString = function(obj) {
            return typeof obj == 'string';
        },
        handlers = {},
        specialEvents = {},
        focusinSupported = 'onfocusin' in window,
        focus = { focus: 'focusin', blur: 'focusout' },
        hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' };

    specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents';

    function zid(element) {
        return element._zid || (element._zid = _zid++);
    }

    function findHandlers(element, event, fn, selector) {
        event = parse(event);
        if (event.ns) var matcher = matcherFor(event.ns);
        return (handlers[zid(element)] || []).filter(function(handler) {
            return handler
                && (!event.e || handler.e == event.e)
                && (!event.ns || matcher.test(handler.ns))
                && (!fn || zid(handler.fn) === zid(fn))
                && (!selector || handler.sel == selector);
        });
    }

    function parse(event) {
        var parts = ('' + event).split('.');
        return { e: parts[0], ns: parts.slice(1).sort().join(' ') };
    }

    function matcherFor(ns) {
        return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)');
    }

    function eventCapture(handler, captureSetting) {
        return handler.del &&
            (!focusinSupported && (handler.e in focus)) ||
            !!captureSetting;
    }

    function realEvent(type) {
        return hover[type] || (focusinSupported && focus[type]) || type;
    }

    function add(element, events, fn, data, selector, delegator, capture) {
        var id = zid(element), set = (handlers[id] || (handlers[id] = []));
        events.split(/\s/).forEach(function(event) {
            if (event == 'ready') return $(document).ready(fn);
            var handler = parse(event);
            handler.fn = fn;
            handler.sel = selector;
            // emulate mouseenter, mouseleave
            if (handler.e in hover) fn = function(e) {
                var related = e.relatedTarget;
                if (!related || (related !== this && !$.contains(this, related)))
                    return handler.fn.apply(this, arguments);
            };
            handler.del = delegator;
            var callback = delegator || fn;
            handler.proxy = function(e) {
                e = compatible(e);
                if (e.isImmediatePropagationStopped()) return;
                e.data = data;
                var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args));
                if (result === false) e.preventDefault(), e.stopPropagation();
                return result;
            };
            handler.i = set.length;
            set.push(handler);
            if ('addEventListener' in element)
                element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture));
        });
    }

    function remove(element, events, fn, selector, capture) {
        var id = zid(element)
        ;(events || '').split(/\s/).forEach(function(event) {
            findHandlers(element, event, fn, selector).forEach(function(handler) {
                delete handlers[id][handler.i];
                if ('removeEventListener' in element)
                    element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture));
            });
        });
    }

    $.event = { add: add, remove: remove };

    $.proxy = function(fn, context) {
        var args = (2 in arguments) && slice.call(arguments, 2);
        if (isFunction(fn)) {
            var proxyFn = function() {
                return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments);
            };
            proxyFn._zid = zid(fn);
            return proxyFn;
        } else if (isString(context)) {
            if (args) {
                args.unshift(fn[context], fn);
                return $.proxy.apply(null, args);
            } else {
                return $.proxy(fn[context], fn);
            }
        } else {
            throw new TypeError('expected function');
        }
    };

    $.fn.bind = function(event, data, callback) {
        return this.on(event, data, callback);
    };
    $.fn.unbind = function(event, callback) {
        return this.off(event, callback);
    };
    $.fn.one = function(event, selector, data, callback) {
        return this.on(event, selector, data, callback, 1);
    };

    var returnTrue = function() {
            return true;
        },
        returnFalse = function() {
            return false;
        },
        ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$|webkitMovement[XY]$)/,
        eventMethods = {
            preventDefault: 'isDefaultPrevented',
            stopImmediatePropagation: 'isImmediatePropagationStopped',
            stopPropagation: 'isPropagationStopped'
        };

    function compatible(event, source) {
        if (source || !event.isDefaultPrevented) {
            source || (source = event);

            $.each(eventMethods, function(name, predicate) {
                var sourceMethod = source[name];
                event[name] = function() {
                    this[predicate] = returnTrue;
                    return sourceMethod && sourceMethod.apply(source, arguments);
                };
                event[predicate] = returnFalse;
            });

            event.timeStamp || (event.timeStamp = Date.now());

            if (source.defaultPrevented !== undefined ? source.defaultPrevented :
                'returnValue' in source ? source.returnValue === false :
                    source.getPreventDefault && source.getPreventDefault())
                event.isDefaultPrevented = returnTrue;
        }
        return event;
    }

    function createProxy(event) {
        var key, proxy = { originalEvent: event };
        for (key in event)
            if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key];

        return compatible(proxy, event);
    }

    $.fn.delegate = function(selector, event, callback) {
        return this.on(event, selector, callback);
    };
    $.fn.undelegate = function(selector, event, callback) {
        return this.off(event, selector, callback);
    };

    $.fn.live = function(event, callback) {
        $(document.body).delegate(this.selector, event, callback);
        return this;
    };
    $.fn.die = function(event, callback) {
        $(document.body).undelegate(this.selector, event, callback);
        return this;
    };

    $.fn.on = function(event, selector, data, callback, one) {
        var autoRemove, delegator, $this = this;
        if (event && !isString(event)) {
            $.each(event, function(type, fn) {
                $this.on(type, selector, data, fn, one);
            });
            return $this;
        }

        if (!isString(selector) && !isFunction(callback) && callback !== false)
            callback = data, data = selector, selector = undefined;
        if (callback === undefined || data === false)
            callback = data, data = undefined;

        if (callback === false) callback = returnFalse;

        return $this.each(function(_, element) {
            if (one) autoRemove = function(e) {
                remove(element, e.type, callback);
                return callback.apply(this, arguments);
            };

            if (selector) delegator = function(e) {
                var evt, match = $(e.target).closest(selector, element).get(0);
                if (match && match !== element) {
                    evt = $.extend(createProxy(e), { currentTarget: match, liveFired: element });
                    return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1)));
                }
            };

            add(element, event, callback, data, selector, delegator || autoRemove);
        });
    };
    $.fn.off = function(event, selector, callback) {
        var $this = this;
        if (event && !isString(event)) {
            $.each(event, function(type, fn) {
                $this.off(type, selector, fn);
            });
            return $this;
        }

        if (!isString(selector) && !isFunction(callback) && callback !== false)
            callback = selector, selector = undefined;

        if (callback === false) callback = returnFalse;

        return $this.each(function() {
            remove(this, event, callback, selector);
        });
    };

    $.fn.trigger = function(event, args) {
        event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event);
        event._args = args;
        return this.each(function() {
            // handle focus(), blur() by calling them directly
            if (event.type in focus && typeof this[event.type] == 'function') this[event.type]();
            // items in the collection might not be DOM elements
            else if ('dispatchEvent' in this) this.dispatchEvent(event);
            else $(this).triggerHandler(event, args);
        });
    };

    // triggers event handlers on current element just as if an event occurred,
    // doesn't trigger an actual event, doesn't bubble
    $.fn.triggerHandler = function(event, args) {
        var e, result;
        this.each(function(i, element) {
            e = createProxy(isString(event) ? $.Event(event) : event);
            e._args = args;
            e.target = element;
            $.each(findHandlers(element, event.type || event), function(i, handler) {
                result = handler.proxy(e);
                if (e.isImmediatePropagationStopped()) return false;
            });
        });
        return result;
    }

    // shortcut methods for `.bind(event, fn)` for each event type
    ;('focusin focusout focus blur load resize scroll unload click dblclick ' +
        'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave ' +
        'change select keydown keypress keyup error').split(' ').forEach(function(event) {
        $.fn[event] = function(callback) {
            return (0 in arguments) ?
                this.bind(event, callback) :
                this.trigger(event);
        };
    });

    $.Event = function(type, props) {
        if (!isString(type)) props = type, type = props.type;
        var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true;
        if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]);
        event.initEvent(type, bubbles, true);
        return compatible(event);
    };

})(Dom7);

//dom7-ajax
;(function($) {
    var jsonpID = +new Date(),
        document = window.document,
        key,
        name,
        scriptTypeRE = /^(?:text|application)\/javascript/i,
        xmlTypeRE = /^(?:text|application)\/xml/i,
        jsonType = 'application/json',
        htmlType = 'text/html',
        blankRE = /^\s*$/,
        originAnchor = document.createElement('a');

    originAnchor.href = window.location.href;

    // trigger a custom event and return false if it was cancelled
    function triggerAndReturn(context, eventName, data) {
        var event = $.Event(eventName);
        $(context).trigger(event, data);
        return !event.isDefaultPrevented();
    }

    // trigger an Ajax "global" event
    function triggerGlobal(settings, context, eventName, data) {
        if (settings.global) return triggerAndReturn(context || document, eventName, data);
    }

    // Number of active Ajax requests
    $.active = 0;

    function ajaxStart(settings) {
        if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart');
    }

    function ajaxStop(settings) {
        if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop');
    }

    // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
    function ajaxBeforeSend(xhr, settings) {
        var context = settings.context;
        if (settings.beforeSend.call(context, xhr, settings) === false ||
            triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
            return false;

        triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]);
    }

    function ajaxSuccess(data, xhr, settings, deferred) {
        var context = settings.context, status = 'success';
        settings.success.call(context, data, status, xhr);
        if (deferred) deferred.resolveWith(context, [data, status, xhr]);
        triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]);
        ajaxComplete(status, xhr, settings);
    }

    // type: "timeout", "error", "abort", "parsererror"
    function ajaxError(error, type, xhr, settings, deferred) {
        var context = settings.context;
        settings.error.call(context, xhr, type, error);
        if (deferred) deferred.rejectWith(context, [xhr, type, error]);
        triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type]);
        ajaxComplete(type, xhr, settings);
    }

    // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
    function ajaxComplete(status, xhr, settings) {
        var context = settings.context;
        settings.complete.call(context, xhr, status);
        triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]);
        ajaxStop(settings);
    }

    function ajaxDataFilter(data, type, settings) {
        if (settings.dataFilter == empty) return data;
        var context = settings.context;
        return settings.dataFilter.call(context, data, type);
    }

    // Empty function, used as default callback
    function empty() {
    }

    $.ajaxJSONP = function(options, deferred) {
        if (!('type' in options)) return $.ajax(options);

        var _callbackName = options.jsonpCallback,
            callbackName = ($.isFunction(_callbackName) ?
                _callbackName() : _callbackName) || ('Zepto' + (jsonpID++)),
            script = document.createElement('script'),
            originalCallback = window[callbackName],
            responseData,
            abort = function(errorType) {
                $(script).triggerHandler('error', errorType || 'abort');
            },
            xhr = { abort: abort }, abortTimeout;

        if (deferred) deferred.promise(xhr);

        $(script).on('load error', function(e, errorType) {
            clearTimeout(abortTimeout);
            $(script).off().remove();

            if (e.type == 'error' || !responseData) {
                ajaxError(null, errorType || 'error', xhr, options, deferred);
            } else {
                ajaxSuccess(responseData[0], xhr, options, deferred);
            }

            window[callbackName] = originalCallback;
            if (responseData && $.isFunction(originalCallback))
                originalCallback(responseData[0]);

            originalCallback = responseData = undefined;
        });

        if (ajaxBeforeSend(xhr, options) === false) {
            abort('abort');
            return xhr;
        }

        window[callbackName] = function() {
            responseData = arguments;
        };

        script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName);
        document.head.appendChild(script);

        if (options.timeout > 0) abortTimeout = setTimeout(function() {
            abort('timeout');
        }, options.timeout);

        return xhr;
    };

    $.ajaxSettings = {
        // Default type of request
        type: 'GET',
        // Callback that is executed before request
        beforeSend: empty,
        // Callback that is executed if the request succeeds
        success: empty,
        // Callback that is executed the the server drops error
        error: empty,
        // Callback that is executed on request complete (both: error and success)
        complete: empty,
        // The context for the callbacks
        context: null,
        // Whether to trigger "global" Ajax events
        global: true,
        // Transport
        xhr: function() {
            return new window.XMLHttpRequest();
        },
        // MIME types mapping
        // IIS returns Javascript as "application/x-javascript"
        accepts: {
            script: 'text/javascript, application/javascript, application/x-javascript',
            json: jsonType,
            xml: 'application/xml, text/xml',
            html: htmlType,
            text: 'text/plain'
        },
        // Whether the request is to another domain
        crossDomain: false,
        // Default timeout
        timeout: 0,
        // Whether data should be serialized to string
        processData: true,
        // Whether the browser should be allowed to cache GET responses
        cache: true,
        //Used to handle the raw response data of XMLHttpRequest.
        //This is a pre-filtering function to sanitize the response.
        //The sanitized response should be returned
        dataFilter: empty
    };

    function mimeToDataType(mime) {
        if (mime) mime = mime.split(';', 2)[0];
        return mime && (mime == htmlType ? 'html' :
            mime == jsonType ? 'json' :
                scriptTypeRE.test(mime) ? 'script' :
                    xmlTypeRE.test(mime) && 'xml') || 'text';
    }

    function appendQuery(url, query) {
        if (query == '') return url;
        return (url + '&' + query).replace(/[&?]{1,2}/, '?');
    }

    // serialize payload and append it to the URL for GET requests
    function serializeData(options) {
        if (options.processData && options.data && $.type(options.data) != 'string')
            options.data = $.param(options.data, options.traditional);
        if (options.data && (!options.type || options.type.toUpperCase() == 'GET' || 'jsonp' == options.dataType))
            options.url = appendQuery(options.url, options.data), options.data = undefined;
    }

    $.ajax = function(options) {
        var settings = $.extend({}, options || {}),
            deferred = $.Deferred && $.Deferred(),
            urlAnchor, hashIndex;
        for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key];

        ajaxStart(settings);

        if (!settings.crossDomain) {
            urlAnchor = document.createElement('a');
            urlAnchor.href = settings.url;
            // cleans up URL for .href (IE only), see https://github.com/madrobby/zepto/pull/1049
            urlAnchor.href = urlAnchor.href;
            settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host);
        }

        if (!settings.url) settings.url = window.location.toString();
        if ((hashIndex = settings.url.indexOf('#')) > -1) settings.url = settings.url.slice(0, hashIndex);
        serializeData(settings);

        var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url);
        if (hasPlaceholder) dataType = 'jsonp';

        if (settings.cache === false || (
            (!options || options.cache !== true) &&
            ('script' == dataType || 'jsonp' == dataType)
        ))
            settings.url = appendQuery(settings.url, '_=' + Date.now());

        if ('jsonp' == dataType) {
            if (!hasPlaceholder)
                settings.url = appendQuery(settings.url,
                    settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?');
            return $.ajaxJSONP(settings, deferred);
        }

        var mime = settings.accepts[dataType],
            headers = {},
            setHeader = function(name, value) {
                headers[name.toLowerCase()] = [name, value];
            },
            protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
            xhr = settings.xhr(),
            nativeSetHeader = xhr.setRequestHeader,
            abortTimeout;

        if (deferred) deferred.promise(xhr);

        if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest');
        setHeader('Accept', mime || '*/*');
        if (mime = settings.mimeType || mime) {
            if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0];
            xhr.overrideMimeType && xhr.overrideMimeType(mime);
        }
        if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET'))
            setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded');

        if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name]);
        xhr.setRequestHeader = setHeader;

        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                xhr.onreadystatechange = empty;
                clearTimeout(abortTimeout);
                var result, error = false;
                if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
                    dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'));
                    if (xhr.responseType == 'arraybuffer' || xhr.responseType == 'blob')
                        result = xhr.response;
                    else {
                        result = xhr.responseText;

                        try {
                            // http://perfectionkills.com/global-eval-what-are-the-options/
                            // sanitize response accordingly if data filter callback provided
                            result = ajaxDataFilter(result, dataType, settings);
                            if (dataType == 'script') (1, eval)(result);
                            else if (dataType == 'xml') result = xhr.responseXML;
                            else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result);
                        } catch (e) {
                            error = e;
                        }

                        if (error) return ajaxError(error, 'parsererror', xhr, settings, deferred);
                    }

                    ajaxSuccess(result, xhr, settings, deferred);
                } else {
                    ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred);
                }
            }
        };

        if (ajaxBeforeSend(xhr, settings) === false) {
            xhr.abort();
            ajaxError(null, 'abort', xhr, settings, deferred);
            return xhr;
        }

        var async = 'async' in settings ? settings.async : true;
        xhr.open(settings.type, settings.url, async, settings.username, settings.password);

        if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name];

        for (name in headers) nativeSetHeader.apply(xhr, headers[name]);

        if (settings.timeout > 0) abortTimeout = setTimeout(function() {
            xhr.onreadystatechange = empty;
            xhr.abort();
            ajaxError(null, 'timeout', xhr, settings, deferred);
        }, settings.timeout);

        // avoid sending empty string (#319)
        xhr.send(settings.data ? settings.data : null);
        return xhr;
    };


    var escape = encodeURIComponent;

    function serialize(params, obj, traditional, scope) {
        var type, array = $.isArray(obj), hash = $.isPlainObject(obj);
        $.each(obj, function(key, value) {
            type = $.type(value);
            if (scope) key = traditional ? scope :
                scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']';
            // handle data in serializeArray() format
            if (!scope && array) params.add(value.name, value.value);
            // recurse into nested objects
            else if (type == 'array' || (!traditional && type == 'object'))
                serialize(params, value, traditional, key);
            else params.add(key, value);
        });
    }

    $.param = function(obj, traditional) {
        var params = [];
        params.add = function(key, value) {
            if ($.isFunction(value)) value = value();
            if (value == null) value = '';
            this.push(escape(key) + '=' + escape(value));
        };
        serialize(params, obj, traditional);
        return params.join('&').replace(/%20/g, '+');
    };
})(Dom7);

//layer mobile
;(function(win, $, undefined) {
    var doc = document, query = 'querySelectorAll', claname = 'getElementsByClassName', S = function(s) {
        return doc[query](s);
    };

    //默认配置
    var config = {
        anim: 'scale',  //默认动画类型 up，down，left，right
        fixed: true,
        touchNo: false,
        shade: true,
        shadeClose: true,
        skin: '',
        type: 0,
        zIndex: -1
    };

    var ready = {
        timer: {},
        end: {}
    };

    var index = 0, classs = ['layui-m-layer'], Layer = function(options) {
        var that = this;
        that.config = $.extend({}, config, options);
        console.log(that.config);
        that.view();
    };

    Layer.prototype.view = function() {
        var that = this, config = that.config, layerbox = doc.createElement('div');
        that.id = layerbox.id = classs[0] + index;
        layerbox.setAttribute('class', classs[0] + ' ' + classs[0] + (config.type || 0));
        layerbox.setAttribute('index', index);
        layerbox.setAttribute('anim', config.anim); //增加：动画名称显示
        layerbox.setAttribute('type', config.type || 0); //增加：type类型显示
        if (config.zIndex != -1) {
            layerbox.setAttribute('style', 'z-index:' + config.zIndex); //增加：最外出z-index设置
        }
        if (!config.fixed) {
            layerbox.setAttribute('style', 'position:static;');
        }
        var title = (function() {
            //标题区域
            var titype = typeof config.title === 'object';
            return config.title
                ? '<h3 style="' + (titype ? config.title[1] : '') + '">' + (titype ? config.title[0] : config.title) + '</h3>'
                : '';
        }());
        var button = (function() {
            //按钮区域
            typeof config.btn === 'string' && (config.btn = [config.btn]);
            var btns = (config.btn || []).length, btndom;
            if (btns === 0 || !config.btn) {
                return '';
            }
            btndom = '<span yes type="1">' + config.btn[0] + '</span>';
            if (btns === 2) {
                btndom = '<span no type="0">' + config.btn[1] + '</span>' + btndom;
            }
            return '<div class="layui-m-layerbtn">' + btndom + '</div>';
        }());
        if (!config.fixed) {
            config.style = config.style || '';
        }
        var scrollTopHeight = doc.documentElement.scrollTop || doc.body.scrollTop;
        layerbox.innerHTML = (config.shade ? '<div ' + (typeof config.shade === 'string' ? 'style="' + config.shade + '"' : '') + ' class="layui-m-layershade"></div>' : '')
            + '<div class="layui-m-layermain" ' + (!config.fixed ? 'style="position:absolute;top:' + scrollTopHeight + 'px;"' : '') + '>'
            + '<div class="layui-m-layersection">'
            + '<div class="layui-m-layerchild ' + (config.skin ? 'layui-m-layer-' + config.skin + ' ' : '') + (config.className ? config.className : '') + ' ' + (config.anim ? 'layui-m-anim-' + config.anim : '') + '" ' + (config.style ? 'style="' + config.style + '"' : '') + '>'
            + title
            + '<div class="layui-m-layercont">' + config.content + '</div>'
            + button
            + '</div>'
            + '</div>'
            + '</div>';

        //同type的层不能共存
        var dialogs = doc[claname](classs[0] + config.type), dialen = dialogs.length;
        if (dialen >= 1) {
            layer.close(dialogs[0].getAttribute('index'));
        }

        document.body.appendChild(layerbox);

        that.index = index++;
        var elem = that.elem = S('#' + that.id)[0];
        config.success && config.success(elem, that.index);

        that.action(config, elem);
    };

    Layer.prototype.action = function(config, elem) {
        var that = this;

        //当滑动弹窗内容时，禁止遮罩底部内容一起滑动
        if (config.touchNo) {
            $('.layui-m-layershade,.layui-m-layermain').on('touchmove', function(e) {
                e.preventDefault();
            });
        }

        //自动关闭
        if (config.time) {
            ready.timer[that.index] = setTimeout(function() {
                layer.close(that.index);
            }, config.time * 1000);
        }

        //确认取消
        if (config.btn) {
            $('.layui-m-layerbtn').on('click', function() {
                var type = $(this).attr('type');
                if (type == 0) {
                    config.no && config.no();
                    layer.close(that.index);
                } else {
                    config.yes ? config.yes(that.index) : layer.close(that.index);
                }
            });
        }

        //点遮罩关闭
        if (config.shade && config.shadeClose) {
            $('.layui-m-layershade').on('click', function() {
                layer.close(that.index);
            });
        }

        config.end && (ready.end[that.index] = config.end);
    };

    win.layer = {
        v: '4.0',
        index: function() {
            return index;
        },
        open: function(options) {
            //核心方法
            var o = new Layer(options || {});
            return o.index;
        },
        close: function(index, flag) {
            //关闭单独layer层
            //flag参数用于强制关闭多个弹出且，当有一个弹窗为type:3的，这样调用layer.closeAll()就不会一次全部关闭，这个是因为transitionend造成的
            var $ibox = $('#' + classs[0] + index);
            if ($ibox.length < 1) return;
            var animName = $ibox.attr('anim');
            var type = $ibox.attr('type');
            if (!flag && type == '3') {
                $ibox.find('.layui-m-layershade').removeClass(animName + '-shade');
                $ibox.find('.layui-m-layerchild').removeClass(animName + '-toggle').on('transitionend webkitTransitionEnd', function() {
                    $ibox.remove();
                    clearTimeout(ready.timer[index]);
                    delete ready.timer[index];
                    typeof ready.end[index] === 'function' && ready.end[index]();
                    delete ready.end[index];
                });
            } else {
                $ibox.remove();
                clearTimeout(ready.timer[index]);
                delete ready.timer[index];
                typeof ready.end[index] === 'function' && ready.end[index]();
                delete ready.end[index];
            }
        },
        closeAll: function(flag) {
            //关闭所有layer层
            var boxs = doc[claname](classs[0]);
            for (var i = 0, len = boxs.length; i < len; i++) {
                layer.close((boxs[0].getAttribute('index') | 0), flag);
            }
        },
        alert: function(param) {
            if (typeof param !== 'string' && typeof param !== 'object') return false;
            let _param = param;
            if (typeof param === 'string') {
                _param = { 'msg': param };
            }
            let {
                anim = 'scale',
                btn = ['确定'],
                msg = '',
                title = '',
                skin = 'weui-dialog',
                style = 'width: 80%;max-width: 300px;',
                onOK = function(i) {
                    layer.close(i);
                }
            } = _param;
            let _html = '<div class="' + (skin + '_bd') + '">' + msg + '</div>';
            layer.open({
                anim: anim,
                btn: btn,
                content: _html,
                className: title ? '' : 'title-no',
                style: style,
                skin: skin,
                shadeClose: false,
                title: title,
                touchNo: true,
                yes: onOK
            });
        },
        msg: function(param) {
            if (typeof param !== 'string' && typeof param !== 'object') return false;
            let _param = param;
            if (typeof param === 'string') {
                _param = { 'msg': param };
            }
            let {
                anim = 'scale',
                direct = 'middle',
                msg = '操作成功',
                style = '',
                skin = '',
                time = 1.5,
                type = 1
            } = _param;
            let _html = '', _className = '';
            if (direct === 'middle') {
                _className = 'weui-toast-msg';
                _html = '<span class="weui-tmsg">' + msg + '</span>';
            } else if (direct === 'bottom') {
                _className = 'weui-toast-msg weui-bottom';
                _html = '<span class="weui-tmsg">' + msg + '</span>';
            }
            layer.open({
                anim: anim,
                content: _html,
                className: _className,
                skin: skin,
                shadeClose: false,
                style: style,
                shade: false,
                time: time,
                type: type
            });
        },
        confirm: function(param) {
            if (typeof param !== 'object') return false;
            let {
                anim = 'scale',
                btn = ['确定', '取消'],
                msg = '',
                title = '',
                skin = 'weui-dialog',
                style = 'width: 80%;max-width: 300px;',
                onOK = function(i) {
                    layer.close(i);
                },
                onCancel = function(i) {
                    layer.close(i);
                }
            } = param;
            let _html = '<div class="' + (skin + '_bd') + '">' + msg + '</div>';
            layer.open({
                anim: anim,
                btn: btn,
                content: _html,
                className: title ? '' : 'title-no',
                style: style,
                skin: skin,
                shadeClose: false,
                title: title,
                touchNo: true,
                yes: onOK,
                no: onCancel
            });
        },
        loading: function(param = {}) {
            if (typeof param !== 'string' && typeof param !== 'object') return false;
            let _param = param;
            if (typeof param === 'string') {
                _param = { 'msg': param };
            }
            let {
                anim = 'scale',
                msg = '数据加载中...',
                style = '',
                skin = '',
                type = 0
            } = _param;
            let _html = '';
            if (skin === 't2') {
                _html += '<span class="van-loading__spinner van-loading__spinner--circular"><svg viewBox="25 25 50 50" class="van-loading__circular"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span>';
                _html += '<p class="weui-toast__content">' + msg + '</p>';

            } else {
                _html += '<i class="weui-loading weui-icon_toast"></i>';
                _html += '<p class="weui-toast__content">' + msg + '</p>';
            }
            return layer.open({
                anim: anim,
                content: _html,
                className: 'weui-toast',
                style: style,
                skin: skin,
                shadeClose: false,
                shade: 'background-color: rgba(0,0,0,0)',
                type: type,
                touchNo: true
            });
        },
        toast: function(param) {
            //toast 用于临时显示某些信息，并且会在数秒后自动消失。这些信息通常是轻量级操作的成功、失败或等待状态信息。
            if (typeof param !== 'string' && typeof param !== 'object') return false;
            let _param = param;
            if (typeof param === 'string') {
                _param = { 'msg': param };
            }
            let {
                anim = 'scale',
                msg = '操作成功',
                style = 'success',
                skin = '',
                time = 2,
                callback = function() {
                }
            } = _param;

            let _className = '';
            switch (style) {
                case 'success':
                    _className = 'weui-icon-success-no-circle';
                    break;
                case 'error':
                    _className = 'weui-icon-cancel';
                    break;
                default:
                    _className = 'weui-icon-success-no-circle';
                    break;
            }
            let _html = '';
            _html += '<i class="' + _className + ' weui-icon_toast"></i>';
            _html += '<p class="weui-toast__content">' + msg + '</p>';
            layer.open({
                anim: anim,
                className: 'weui-toast',
                content: _html,
                skin: skin,
                shadeClose: false,
                shade: 'background-color: rgba(0,0,0,0)',
                time: time,
                touchNo: true,
                end: function() {
                    callback.call(this);
                }
            });
        },
        popup: function(opt) {
            let defaults = {
                direction: 'bottom',
                anim: 'weui-actionsheet',
                className: '',
                content: '',
                shade: 'background-color: rgb(0, 0, 0);opacity: 0;transition: all .3s;-webkit-transition: all .3s;',
                shadeClose: !0,
                style: '',
                touchNo: true,
                zIndex: -1,
                success: null,
                end: null
            };
            let options = $.extend({}, defaults, opt);
            let animDirect = [{
                anim: 'weui-actionsheet',
                direction: 'bottom',
                style: ''
            }, {
                anim: 'weui-actionsheet-top',
                direction: 'top',
                style: ''
            }, {
                anim: 'weui-actionsheet-left',
                direction: 'left',
                style: 'width: 76%;'
            }, {
                anim: 'weui-actionsheet-right',
                direction: 'right',
                style: 'width: 76%;'
            }].find(function(item) {
                return item.direction === options.direction;
            });
            options.anim = animDirect.anim;
            options.style = !options.style ? animDirect.style : options.style;

            let className = options.className ? (options.anim + ' ' + options.className) : options.anim;
            layer.open({
                anim: options.anim,
                className: className,
                content: options.content,
                shade: options.shade,
                shadeClose: options.shadeClose,
                style: options.style,
                type: 3,
                touchNo: options.touchNo,
                zIndex: options.zIndex,
                success: function(el, index) {
                    $('.' + options.anim).width();//强制取值一次，防止上下代码合并执行，否则动画效果无效
                    $('.' + options.anim).addClass(options.anim + '-toggle');

                    $('.layui-m-layershade').width();//强制取值一次，防止上下代码合并执行，否则动画效果无效
                    $('.layui-m-layershade').addClass(options.anim + '-shade');

                    if ($.isFunction(options.success)) {
                        options.success.apply(this, [el, index]);
                    }
                },
                end: function() {
                    if ($.isFunction(options.end)) {
                        options.end.call();
                    }
                }
            });
        },
        actions: function(opt) {
            var defaults = {
                cancleText: '取消',
                style: 'background-color:#efeff4;',
                styleTitle: '',
                title: '',
                touchNo: true,
                zIndex: -1,
                actions: [{
                    text: '操作2',
                    style: '',
                    onClick: null
                }]
            };
            var options = $.extend({}, defaults, opt);
            var html = '';
            if (options.title) {
                html += '<div class="weui-actionsheet-title" style="' + options.styleTitle + '">' + options.title + '</div>';
            }
            html += '<ul class="menu-list">';
            $.each(options.actions, function(index, item) {
                html += '<li style="' + item.style + '">' + item.text + '</li>';
            });
            html += '</ul>';
            html += '<p class="btn-cancle">' + options.cancleText + '</p>';
            layer.popup({
                content: html,
                style: options.style,
                touchNo: options.touchNo,
                zIndex: options.zIndex,
                success: function(el, index) {
                    $('.weui-actionsheet .menu-list li').each(function(index) {
                        var onClick = options.actions[index].onClick;
                        if ($.isFunction(onClick)) {
                            $(this).on('click', onClick);
                        }
                    });
                    $('.weui-actionsheet .btn-cancle').on('click', function() {
                        layer.close(index);
                    });
                }
            });
        },
        photoLayer: function(opt) {
            var defaults = {
                btnClose: false,
                className: '',
                classNameDefault: 'photo-layer',
                shade: true,
                shadeClose: true,
                style: 'width:90%;max-width:640px;background-color:transparent;',
                items: [
                    // {
                    //     'img':'',
                    //     'className':null,
                    //     'link':null,
                    // },
                    //img:'',//支持string,此时为img路径
                ],
                success: null
            };
            var options = $.extend({}, defaults, opt);
            var html = '<div class="' + options.classNameDefault + ' ' + options.className + '">';
            if (options.items.length > 0) {
                html += '<ul>';
                for (var i = 0; i < options.items.length; i++) {
                    if (typeof options.items[i] === 'string') {
                        html += '<li><img src="' + options.items[i] + '" width="100%" /></li>';
                    } else if (typeof options.items[i] === 'object' && Object.prototype.toString.call(options.items[i]) === '[object Object]') {
                        if (options.items[i].img) {
                            if (options.items[i].link) {
                                html += '<li class="' + (options.items[i].className ? options.items[i].className : '') + '"><a href="' + options.items[i].link + '"><img src="' + options.items[i].img + '" width="100%" /></a></li>';
                            } else {
                                html += '<li class="' + (options.items[i].className ? options.items[i].className : '') + '"><img src="' + options.items[i].img + '" width="100%" /></li>';
                            }
                        }
                    }
                }
                html += '</ul>';
                if (options.btnClose) {
                    html += '<span class="layer-close"><i class="weui-icon-cancel"></i></span>';
                }
            }
            html += '</div>';
            var className = options.className ? options.classNameDefault + '-wrap ' + options.className + '-wrap' : options.classNameDefault + '-wrap';
            return layer.open({
                type: 1,
                shade: options.shade,
                shadeClose: options.shadeClose,
                style: options.style,
                className: className,
                content: html,
                success: function(el, index) {
                    var $close = $('.' + options.classNameDefault + '-wrap .close,' + '.' + options.classNameDefault + '-wrap .layer-close');
                    $close.on('click', function() {
                        layer.close(index);
                        return false;
                    });

                    if ($.isFunction(options.success)) {
                        options.success.apply(this, null);
                    }
                }
            });
        }
    };

    'function' == typeof define ? define(function() {
        return layer;
    }) : function() {
        var js = document.scripts, script = js[js.length - 1], jsPath = script.src;
        var path = jsPath.substring(0, jsPath.lastIndexOf('/') + 1);

        //如果合并方式，则需要单独引入layer.css
        if (script.getAttribute('merge')) return;

        document.head.appendChild(function() {
            var link = doc.createElement('link');
            link.href = path + 'need/layer.min.css?v=4.0';
            link.type = 'text/css';
            link.rel = 'styleSheet';
            link.id = 'layermcss';
            return link;
        }());
    }();
})(window, Dom7);

//layer select
;(function($, layer, undefined) {
    $.fn.select = function(option) {
        var defaults = {
            title: null,
            multi: false,
            items: null,
            autoClose: true,
            input: null,
            closeText: '确定',
            max: 3,
            min: 2,
            split: ','
        };
        var options = $.extend({}, defaults, option);
        if (!options.items || !options.items.length) return;
        options.items = options.items.map(function(d, i) {
            if (typeof d === typeof 'a') {
                return {
                    title: d,
                    value: d
                };
            } else {
                return d;
            }
        });
        return this.each(function() {
            var _self = $(this);
            if (options.input) {
                _self.val(options.input);
            }
            _self.on('click', function() {
                var oldValue = $.trim($(this).val());
                var multiVal = [];
                if (oldValue) {
                    oldValue = oldValue.split(options.split);
                    if (options.multi) {
                        multiVal = oldValue;
                    }
                }
                var isShowClose = true;
                if (!options.multi && options.autoClose) {
                    isShowClose = false;
                }
                var htmlTitle = '<div class="toolbar"><div class="toolbar-inner"><h2 class="title">' + options.title + '</h2><a class="picker-button close-select ' + (isShowClose ? '' : 'hide') + '" href="javascript:;">' + options.closeText + '</a></div></div>';
                var htmlCon = '<div class="weui-cells"><ul>';
                var className;
                $.each(options.items, function(index, item) {
                    if (oldValue && ($.inArray(item.value, oldValue) != -1)) {
                        className = options.multi ? 'weui-icon-checked-multi check' : 'weui-icon-checked';
                    } else {
                        className = options.multi ? 'weui-icon-checked-multi' : 'weui-icon-checked hide';
                    }
                    htmlCon += '<li data-val="' + item.value + '">' + item.title + '<i class="' + className + '"></i></li>';
                });
                htmlCon += '</ul></div>';
                layer.popup({
                    className: 'layer-select-wrap',
                    content: htmlTitle + htmlCon,
                    success: function() {
                        $('.layer-select-wrap .weui-cells li').on('click', function() {
                            var tempVal = $.trim($(this).data('val'));
                            //单选
                            if (!options.multi) {
                                var siblings = $(this).siblings().find('.weui-icon-checked');
                                siblings.each(function() {
                                    if (!$(this).hasClass('hide')) {
                                        $(this).addClass('hide');
                                    }
                                });
                                $(this).find('.weui-icon-checked').removeClass('hide');
                                _self.val(tempVal);
                                if (options.autoClose) {
                                    layer.closeAll();
                                }
                            } else {
                                //多选
                                var multiLength = multiVal.length;
                                var check = $(this).find('.weui-icon-checked-multi');
                                if (check.hasClass('check')) {
                                    if (multiLength <= options.min) {
                                        //alert('请至少选择' + options.min + '个');
                                        layer.msg('请至少选择' + options.min + '个', 'bottom');
                                        return;
                                    }
                                    check.removeClass('check');
                                    $.each(multiVal, function(index, item) {
                                        if (item == tempVal) {
                                            multiVal.splice(index, 1);
                                        }
                                    });
                                } else {
                                    if (multiLength >= options.max) {
                                        //alert('最多只能选择' + options.max + '个');
                                        layer.msg('最多只能选择' + options.max + '个', 'bottom');
                                        return;
                                    }
                                    check.addClass('check');
                                    multiVal.push(tempVal);
                                }
                                _self.val(multiVal.join(options.split));
                            }
                        });
                        //右上角确定按钮
                        $('.layer-select-wrap .close-select').on('click', function() {
                            layer.closeAll();
                        });
                        $('.layui-m-layershade').on('touchmove', function(e) {
                            e.preventDefault();
                        });
                    }
                });
            });
        });
    };
})(Dom7, layer);

//laytpl
;(function(window, $, undefined) {
    'use strict';

    var config = {
        open: '{{',
        close: '}}'
    };

    var tool = {
        exp: function(str) {
            return new RegExp(str, 'g');
        },
        //匹配满足规则内容
        query: function(type, _, __) {
            var types = [
                '#([\\s\\S])+?',   //js语句
                '([^{#}])*?' //普通字段
            ][type || 0];
            return exp((_ || '') + config.open + types + config.close + (__ || ''));
        },
        escape: function(html) {
            return String(html || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&amp;')
                .replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;').replace(/"/g, '&quot;');
        },
        error: function(e, tplog) {
            var error = 'Laytpl Error: ';
            typeof console === 'object' && console.error(error + e + '\n' + (tplog || ''));
            return error + e;
        }
    };

    var exp = tool.exp, Tpl = function(tpl) {
        this.tpl = tpl;
    };

    Tpl.pt = Tpl.prototype;

    window.errors = 0;

    //编译模版
    Tpl.pt.parse = function(tpl, data) {
        var that = this, tplog = tpl;
        var jss = exp('^' + config.open + '#', ''), jsse = exp(config.close + '$', '');
        tpl = tpl.replace(/\s+|\r|\t|\n/g, ' ')
            .replace(exp(config.open + '#'), config.open + '# ')
            .replace(exp(config.close + '}'), '} ' + config.close).replace(/\\/g, '\\\\')

            //不匹配指定区域的内容
            .replace(exp(config.open + '!(.+?)!' + config.close), function(str) {
                str = str.replace(exp('^' + config.open + '!'), '')
                    .replace(exp('!' + config.close), '')
                    .replace(exp(config.open + '|' + config.close), function(tag) {
                        return tag.replace(/(.)/g, '\\$1');
                    });
                return str;
            })

            //匹配JS规则内容
            .replace(/(?="|')/g, '\\').replace(tool.query(), function(str) {
                str = str.replace(jss, '').replace(jsse, '').replace(/&lt;/g, '<').replace(/&gt;/g, '>');

                return '";' + str.replace(/\\(.)/g, '$1') + ';view+="';
            })

            //匹配普通字段
            .replace(tool.query(1), function(str) {
                var start = '"+(';
                if (str.replace(/\s/g, '') === config.open + config.close) {
                    return '';
                }
                str = str.replace(exp(config.open + '|' + config.close), '');
                if (/^=/.test(str)) {
                    str = str.replace(/^=/, '');
                    start = '"+_escape_(';
                }
                return start + str.replace(/\\(.)/g, '$1') + ')+"';
            });

        tpl = '"use strict";var view = "' + tpl + '";return view;';

        try {
            that.cache = tpl = new Function('d, _escape_', tpl);
            return tpl(data, tool.escape);
        } catch (e) {
            delete that.cache;
            return tool.error(e, tplog);
        }
    };

    Tpl.pt.render = function(data, callback) {
        var that = this, tpl;
        if (!data) return tool.error('no data');
        tpl = that.cache ? that.cache(data, tool.escape) : that.parse(that.tpl, data);
        if (!callback) return tpl;
        callback(tpl);
    };


    var laytpl = function(tpl) {
        if (typeof tpl !== 'string') return tool.error('Template not found');
        return new Tpl(tpl);
    };

    laytpl.config = function(options) {
        options = options || {};
        for (var i in options) {
            config[i] = options[i];
        }
    };

    laytpl.each = function(object, callback) {
        var i, key;
        for (i = 0; i < object.length; i++)
            if (callback.call(object[i], i, object[i]) === false) return object;
        return object;
    };

    laytpl.v = '1.2.0';

    window.laytpl = laytpl;

})(window, Dom7);

//listview
;(function(window, $, undefined) {
    var laytpl = window.laytpl;

    //构造函数
    function Listview(ele, opts) {
        var _self = this;
        _self.ele = ele;
        _self.opts = opts;
        _self.init();
    }

    Listview.prototype.init = function() {
        var _self = this;
        //处理摸版标签
        _self.tpl = _self.opts.tpl ? _self.opts.tpl : $(_self.ele).find('template').html();
        _self.opts.empty ? $(_self.ele).empty2(true) : '';
        var _listcontainer = $(_self.ele).find('.' + _self.opts.classWrapper);
        if (_listcontainer.length > 0) {
            _self.listcontainer = _listcontainer[0];
        } else {
            var listcontainer = document.createElement('div');
            listcontainer.className = _self.opts.classWrapper;
            _self.ele.appendChild(listcontainer);
            _self.listcontainer = listcontainer;
        }

        //处理数据
        if (_self.opts.url) {
            //ajax
            _self.loaddata();

            //滚动分页加载
            if (_self.opts.isScrollPage) {
                var _scrollDom = _self.opts.scrollDom ? _self.opts.scrollDom : _self.ele;
                $(_scrollDom).infinite().on('infinite', function() {
                    _self.loaddata();
                });
            }
        } else {
            if (!_self.opts.data) return false;
            var dataList = _self.opts.data;
            if (_self.opts.keyEach && $.isObject(_self.opts.data) && _self.opts.data[_self.opts.keyEach]) {
                dataList = _self.opts.data[_self.opts.keyEach];
            }
            _self.dataList = $.isArray(dataList) ? dataList : [dataList];
            _self.filldata();
            if ($.isFunction(_self.opts.loadsuccess)) {
                _self.opts.loadsuccess.call(_self.listcontainer, _self.dataList);
            }
        }
    };

    Listview.prototype.loaddata = function() {
        var _self = this;
        if (_self.loading) return;
        _self.loading = true;
        $.ajax({
            'type': _self.opts.extraParams.type,
            'url': _self.opts.url,
            'data': _self.opts.extraParams.data,
            'success': function(data) {
                if (data.ResultCode == '0') {
                    var dataList = data;
                    if (_self.opts.keyEach && $.isObject(data) && data[_self.opts.keyEach]) {
                        dataList = data[_self.opts.keyEach];
                    }
                    _self.dataList = $.isArray(dataList) ? dataList : [dataList];
                    _self.filldata();

                    //loadsuccess回调函数
                    if ($.isFunction(_self.opts.loadsuccess)) {
                        _self.opts.loadsuccess.call(_self.listcontainer, _self.dataList);
                    }

                    //滚动分页加载
                    if (_self.opts.isScrollPage) {
                        var totalList = data.Total; //总记录数
                        var totalPage = Math.ceil(totalList / _self.opts.extraParams.data.pageSize);
                        var _scrollDom = _self.opts.scrollDom ? _self.opts.scrollDom : _self.ele;
                        if (totalPage > _self.opts.extraParams.data.pageIndex + 1) {
                            $('.weui-loadmore').removeClass('hide');
                        } else {
                            $(_scrollDom).destroyInfinite();
                            $('.weui-loadmore').addClass('hide');
                        }
                        _self.opts.extraParams.data.pageIndex++;
                    }

                } else {
                    console.log(data.ErrMsg);
                }
            },
            'error': function() {
            },
            'complete': function() {
                _self.loading = false;
            }
        });
    };

    Listview.prototype.filldata = function() {
        var _self = this;
        var _data = _self.dataList;
        var keyarr = [];
        for (var key in _data[0]) {
            keyarr.push(key);
        }
        for (var i = 0; i < _data.length; i++) {
            _self.addlistitem(keyarr, _data[i], i);
        }
    };

    Listview.prototype.addlistitem = function(keyarr, dataitem, i) {
        var _self = this;
        dataitem.rowIndex = i;
        var _tpl = laytpl(_self.tpl).render(dataitem);
        var listitem = document.createElement('div');
        listitem.className = _self.opts.classItem;
        listitem.innerHTML = _tpl;
        if (_self.opts.itemTap) {
            $(listitem).on('click', function(event) {
                _self.opts.itemTap.call(this, listitem, dataitem, _self.dataList, event);
            });
        }
        _self.listcontainer.appendChild(listitem);
        return true;
    };

    $.fn.listview = function(setting) {
        var defaults = {
            'tpl': null,
            'url': null,
            'extraParams': {
                'type': 'get',
                'data': {
                    'pageIndex': 1,
                    'pageSize': 11
                }
            },
            'isScrollPage': false,
            'scrollDom': 'body',
            'data': null,
            'keyEach': null,
            'classWrapper': 'listviews',
            'classItem': 'item-listview',
            'itemTap': null,
            'empty': false,
            'loadsuccess': null
        };
        var options = $.extend({}, defaults, setting);
        return this.each(function() {
            var el = new Listview(this, options);
        });
    };
})(window, Dom7);

//infinite
;(function($) {
    'use strict';

    var Infinite = function(el, distance) {
        this.container = $(el);
        this.container.data('infinite', this);
        this.distance = distance || 50;
        this.attachEvents();
    };

    //定义scroll方法
    Infinite.prototype.scroll = function() {
        var container = this.container;
        var scrollContainer = (container[0].tagName.toUpperCase() === 'BODY' ? $(document) : container);
        var _scrollTop = scrollContainer.scrollTop();
        //判断滚动条距离底部多少距离
        var offset = container.scrollHeight() - (container.height() + _scrollTop);
        //达到最小距离则触发自定义事件infinite，执行相应加载ajax代码
        if (offset <= this.distance) {
            container.trigger('infinite');
        }
    };

    //定义attachEvents方法
    Infinite.prototype.attachEvents = function(off) {
        var el = this.container;
        var scrollContainer = (el[0].tagName.toUpperCase() === 'BODY' ? $(document) : el);
        //绑定scroll事件,同等于scrollContainer.on('scroll',function(){})
        //scrollContainer['on']、scrollContainer['of']等同于scrollContainer.on、scrollContainer.off
        //$.proxy(this.scroll, this)给scrollContainer.on绑定事件代理this.scroll方法，使用当前上下文环境
        scrollContainer[off ? 'off' : 'on']('scroll', $.proxy(this.scroll, this));
    };

    Infinite.prototype.detachEvents = function() {
        this.attachEvents(true);
    };

    $.fn.infinite = function(distance) {
        return this.each(function() {
            new Infinite(this, distance);
        });
    };

    $.fn.destroyInfinite = function() {
        return this.each(function() {
            var infinite = $(this).data('infinite');
            if (infinite && infinite.detachEvents) infinite.detachEvents();
        });
    };

    $.fn.scrollHeight = function() {
        return this[0].scrollHeight;
    };

})(Dom7);

//pullToRefresh
;(function($) {
    'use strict';

    var PTR = function(el) {
        this.container = $(el);
        this.distance = 50;

        this.attachEvents();
    };

    PTR.prototype.touchStart = function(e) {
        if (this.container.hasClass('refreshing')) return;
        console.log(this.container.scrollTop());
        var p = $.getTouchPosition(e);
        this.start = p;
        this.diffX = this.diffY = 0;
    };

    PTR.prototype.touchMove = function(e) {
        if (this.container.hasClass('refreshing')) return;
        if (!this.start) return false;
        console.log(this.container.scrollTop());
        if (this.container.scrollTop() > 0) return;
        var p = $.getTouchPosition(e);
        this.diffX = p.x - this.start.x;
        this.diffY = p.y - this.start.y;
        if (this.diffY < 0) return;
        this.container.addClass('touching');
        e.preventDefault();
        e.stopPropagation();
        this.diffY = Math.pow(this.diffY, 0.8);
        this.container.css('transform', 'translate3d(0, ' + this.diffY + 'px, 0)');

        if (this.diffY < this.distance) {
            this.container.removeClass('pull-up').addClass('pull-down');
        } else {
            this.container.removeClass('pull-down').addClass('pull-up');
        }
    };

    PTR.prototype.touchEnd = function() {
        this.start = false;
        if (this.diffY <= 0 || this.container.hasClass('refreshing')) return;
        this.container.removeClass('touching');
        this.container.removeClass('pull-down pull-up');
        this.container.css('transform', '');
        if (Math.abs(this.diffY) <= this.distance) {
        } else {
            this.container.addClass('refreshing');
            this.container.trigger('pull-to-refresh');
        }
    };

    PTR.prototype.attachEvents = function() {
        var el = this.container;
        el.addClass('weui-pull-to-refresh');
        el.on($.touchEvents().start, $.proxy(this.touchStart, this));
        el.on($.touchEvents().move, $.proxy(this.touchMove, this));
        el.on($.touchEvents().end, $.proxy(this.touchEnd, this));
    };

    var pullToRefresh = function(el) {
        new PTR(el);
    };

    var pullToRefreshDone = function(el) {
        $(el).removeClass('refreshing');
    };

    $.fn.pullToRefresh = function() {
        return this.each(function() {
            pullToRefresh(this);
        });
    };

    $.fn.pullToRefreshDone = function() {
        return this.each(function() {
            pullToRefreshDone(this);
        });
    };

})(Dom7);
